package com.atguigu.controller;

import com.atguigu.entity.Tiger;
import com.atguigu.service.api.TigerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class TigerController {
	@Autowired
	private TigerService tigerService;

	@GetMapping("/test/getTigerById")
	public String getTigerInfo(
			@RequestParam Integer tigerId
	) {
		Tiger tiger = tigerService.getTigerById(tigerId);
		return tiger.toString();
	}

	@PutMapping("/test/updateTiger")
	public String updateTiger(
			@RequestBody Tiger tiger
	) {
		// 是早点截断流程早点合适,还是分层逻辑更优先合适?
		Tiger tigerOrigin = tigerService.getTigerById(tiger.getTigerId());
		if (tigerOrigin.getTigerId() == null) {
			return "tiger id can not be null";
		}
		tigerService.updateTiger(tiger);
		return  "Origin info: " + tigerOrigin.toString();
	}
}
